/**
 * 1.该文件是用于为Count组件服务的Reducer, Reducer的本质是一个函数
 * 2.reducer函数会接到两个参数, 分别是之前的状态(prevState)、动作对象(action)
 */
import { INCREMENT, DECREMENT } from "./constant"

const initState = 0
export default function countReducer(prevState=initState,action){
  console.log(prevState)
  //if(prevState === undefined) prevState = 0
  const { type, data } = action
  switch (type) {
    case INCREMENT:
      return prevState + data
    case DECREMENT:
      return prevState - data
    default:
      return prevState
  }
}
